@echo off

"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe > temp.txt
for /f %%a in (temp.txt) do set MSBuild=%%a

set version="0.0.1"
pushd ..\source
if not "%~1"=="/a" (
	echo Please select the SDK platform:
	echo [A]Build for all products [B]Build for Gdmp [C]Build for Gap
	choice /c abc /n /cs
	if %errorlevel%==1 goto aa
	if %errorlevel%==2 goto bb
	if %errorlevel%==3 goto cc
	if not "%~1"=="" (
		set version=%~1
	) else (
		echo Please input the version number
		echo format:[YEAR].[Main].[Sub], e.g: 24.0.1
		set /p version=
	)
) else ( 
	if not "%~2"=="" (
		set version=%~2
	) else (
		echo Please input the version number
		echo format:[YEAR].[Main].[Sub], e.g: 24.0.1
		set /p version=
	)
)
set versionFolder=..\bin\%version%
if not exist "%versionFolder%" (
	mkdir %versionFolder%
)

"%MSBUILD%" Glodon.Lookup\Glodon.Lookup.csproj /t:Clean;Build /p:Configuration=ReleaseGdmp /p:Platform=x64
"%MSBUILD%" Glodon.Lookup\Glodon.Lookup.csproj /t:Clean;Build /p:Configuration=ReleaseGap /p:Platform=x64
"%MSBUILD%" Glodon.Lookup.Setup\Glodon.Lookup.Setup.wixproj /t:Clean;Build /p:Configuration=ReleaseGdmp /p:Platform=x64
"%MSBUILD%" Glodon.Lookup.Setup\Glodon.Lookup.Setup.wixproj /t:Clean;Build /p:Configuration=ReleaseGap /p:Platform=x64
set targetPathGdmp=..\bin\ReleaseGdmp
if exist "%targetPathGdmp%" (
	rmdir %targetPathGdmp% /s /q
)

xcopy Glodon.Lookup.Setup\bin\x64\ReleaseGdmp\GLookup.msi %versionFolder%\GLookup_Gdmp_X64_%version%.msi* /y

set targetPathGap=..\bin\ReleaseGap
if exist "%targetPathGap%" (
	rmdir %targetPathGap% /s /q
)

xcopy Glodon.Lookup.Setup\bin\x64\ReleaseGap\GLookup.msi %versionFolder%\GLookup_Gap_X64_%version%.msi* /y
goto end

"%MSBUILD%" Glodon.Lookup\Glodon.Lookup.csproj /t:Clean;Build /p:Configuration=ReleaseGdmp /p:Platform=x64
"%MSBUILD%" Glodon.Lookup.Setup\Glodon.Lookup.Setup.wixproj /t:Clean;Build /p:Configuration=ReleaseGdmp /p:Platform=x64
del ..\bin\* /s /q
set targetPathGdmp=..\bin\ReleaseGdmp
if exist "%targetPathGdmp%" (
	rmdir %targetPathGdmp% /s /q
)
xcopy Glodon.Lookup.Setup\bin\x64\ReleaseGdmp\GLookup.msi %versionFolder%\GLookup_Gdmp_X64_%version%.msi* /y
goto end

"%MSBUILD%" Glodon.Lookup\Glodon.Lookup.csproj /t:Clean;Build /p:Configuration=ReleaseGap /p:Platform=x64
"%MSBUILD%" Glodon.Lookup.Setup\Glodon.Lookup.Setup.wixproj /t:Clean;Build /p:Configuration=ReleaseGap /p:Platform=x64
del ..\bin\* /s /q
set targetPathGap=..\bin\ReleaseGap
if exist "%targetPathGap%" (
	rmdir %targetPathGap% /s /q
)
xcopy Glodon.Lookup.Setup\bin\x64\ReleaseGap\GLookup.msi %versionFolder%\GLookup_Gap_X64_%version%.msi* /y
:end
